package com.tianqu.tms.www.cardect.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.www.cardect.controller.CarWDPersonToIpadConfirmController;
import com.tianqu.tms.www.cardect.viewhelper.CarWDPersonTopListViewHelper;
/**
 * 
 * 待检测（人工）转Ipad录入Action(批量)
 * 
 * @author tianshifu
 *
 */
public class CarWDPersonToIpadConfirmAction extends TmsAction {

	private Logger logger = Logger.getLogger(CarWDPersonToIpadConfirmAction.class);//log
	private static final String ALLOCATEID = "carSerial";//定义页面checkbox的property
	private static final String ADDMODE    = "addModel";//转录入模式 3 人工
	
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		
		//获取页面checkbox选中项
		String[] checkbox = request.getParameterValues(ALLOCATEID);

		//这个地方需要对checkbox进行处理 去掉“false”
		String checkValue = "";
		String checkVV = "";
		if(checkbox!=null)
		{
			for(int i=0;i<checkbox.length;i++)
			{
				checkValue = checkbox[i];
				if(!checkValue.equals("false"))
				{
					checkVV += checkValue+",";
				}
			}
		}
		
		if(checkbox == null || "".equals(checkVV))
		{
			//说明没有选中，向前台打出提示
			setErrorsToRequest(request, TmsConstants.IA001 ,null);
			return mapping.getInputForward();
		}
		
		uc.setAttribute(ALLOCATEID, checkbox);//将选中车辆ID数组放到uc中在下个action中处理
		uc.setAttribute(ADDMODE, "2");//IPAD
		//
		CarWDPersonToIpadConfirmController controller = new CarWDPersonToIpadConfirmController();
		controller.execute(uc);
		
		CarWDPersonTopListViewHelper view = (CarWDPersonTopListViewHelper)uc.getAttribute(TmsConstants.VIEWHELP);
				
		request.setAttribute(TmsConstants.VIEWHELP, view);
		uc.removeAttribute(TmsConstants.VIEWHELP);//清空viewhelp
		logger.debug(this.getClass().getName() + "#doAction was completed.");		
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
